ifconfig command
ifconfig
- configure a network interface
The ifconfig
command in Linux is a traditional tool used to display and configure network interfaces (e.g., Ethernet, Wi-Fi). It shows details like IP addresses, MAC addresses, and interface status, and can enable, disable, or modify network settings. While newer systems prefer ip
(from iproute2
), ifconfig
is still widely used on older systems or where net-tools
is installed.
Note: ifconfig
may not be installed by default on modern distros (e.g., Ubuntu 20.04+). Install it with sudo apt install net-tools
or use ip addr
instead.
Usage: ifconfig [-v] [-a] [-s] [interface] [options]
interface
: The network interface (e.g.,eth0
,wlan0
; optional).options
: Flags or parameters to configure the interface.
Common Options
Option/Action | Description |
---|---|
(no option) | List all active interfaces |
up | Enable an interface |
down | Disable an interface |
netmask | Set subnet mask |
hw ether | Set MAC address |
-a | Show all interfaces (active or inactive) |
Examples
-
Basic Usage
Run
ifconfig
without arguments to list all active network interfaces.ifconfig
-
Output (example):
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
ether 00:14:22:01:23:45 txqueuelen 1000 (Ethernet)
RX packets 1234 bytes 567890 (567.8 KB)
TX packets 567 bytes 123456 (123.4 KB)
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback) -
Explanation:
eth0
: Ethernet interface.inet 192.168.1.100
: IP address.netmask 255.255.255.0
: Subnet mask.ether 00:14:22:01:23:45
: MAC address.lo
: Loopback interface (localhost).
-
-
Specific Interface
Pass an interface name to see only its details.
ifconfig eth0
- Shows only
eth0
’s info.
- Shows only
-
Enabling an Interface
Use
up
to activate an interface.sudo ifconfig eth0 up
- Brings
eth0
online (requires root privileges).
- Brings
-
Disabling an Interface
Use
down
to deactivate an interface.sudo ifconfig eth0 down
- Shuts off
eth0
.
- Shuts off
-
Setting an IP Address
Assign an IP address and optionally a netmask.
sudo ifconfig eth0 192.168.1.200 netmask 255.255.255.0
- Sets
eth0
to IP192.168.1.200
with subnet255.255.255.0
.
- Sets
-
Changing MAC Address (Spoofing)
Modify the hardware (MAC) address with
hw ether
.sudo ifconfig eth0 hw ether 00:11:22:33:44:55
- Changes
eth0
’s MAC address (interface must be down first).
- Changes
To get help related to the ifconfig
command use --help
option
$ ifconfig --help
Usage:
ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
[add <address>[/<prefixlen>]]
[del <address>[/<prefixlen>]]
[[-]broadcast [<address>]] [[-]pointopoint [<address>]]
[netmask <address>] [dstaddr <address>] [tunnel <address>]
[outfill <NN>] [keepalive <NN>]
[hw <HW> <address>] [mtu <NN>]
[[-]trailers] [[-]arp] [[-]allmulti]
[multicast] [[-]promisc]
[mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]
[txqueuelen <NN>]
[[-]dynamic]
[up|down] ...
<HW>=Hardware Type.
List of possible hardware types:
loop (Local Loopback) slip (Serial Line IP) cslip (VJ Serial Line IP)
slip6 (6-bit Serial Line IP) cslip6 (VJ 6-bit Serial Line IP) adaptive (Adaptive Serial Line IP)
ash (Ash) ether (Ethernet) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) rose (AMPR ROSE) tunnel (IPIP Tunnel)
ppp (Point-to-Point Protocol) hdlc ((Cisco)-HDLC) lapb (LAPB)
arcnet (ARCnet) dlci (Frame Relay DLCI) frad (Frame Relay Access Device)
sit (IPv6-in-IPv4) fddi (Fiber Distributed Data Interface) hippi (HIPPI)
irda (IrLAP) ec (Econet) x25 (generic X.25)
eui64 (Generic EUI-64)
<AF>=Address family. Default: inet
List of possible address families:
unix (UNIX Domain) inet (DARPA Internet) inet6 (IPv6)
ax25 (AMPR AX.25) netrom (AMPR NET/ROM) rose (AMPR ROSE)
ipx (Novell IPX) ddp (Appletalk DDP) ec (Econet)
ash (Ash) x25 (CCITT X.25)
For more details, check the manual with man ifconfig